﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

/// <summary>
/// Summary description for AdHocSql
/// </summary>
[XmlRoot(ElementName = "AdHocSql", Namespace = "http://www.galaware.com/adhocsql/1.0", IsNullable = false)]
public class AdHocSql
{
	#region Private Properties
	private List<AdHocSqlConnection> m_oConnections;
	private List<AdHocSqlStatement> m_oStatements;
	#endregion

	#region Constructors
	public AdHocSql()
	{
		m_oConnections = new List<AdHocSqlConnection>();
		m_oStatements = new List<AdHocSqlStatement>();
	}
	#endregion

	#region Public Properties
	[XmlArray(ElementName = "Connections", IsNullable = true),
	 XmlArrayItem(ElementName = "Connection", IsNullable = true, Type = typeof(AdHocSqlConnection))]
	public List<AdHocSqlConnection> Connections
	{
		get { return m_oConnections; }
		set { m_oConnections = value; }
	}
	[XmlArray(ElementName = "SqlStatements", IsNullable = true),
	 XmlArrayItem(ElementName = "Sql", IsNullable = true, Type = typeof(AdHocSqlStatement))]
	public List<AdHocSqlStatement> SqlStatements
	{
		get { return m_oStatements; }
		set { m_oStatements = value; }
	}
	#endregion

	#region Private Methods
	#endregion
}

public class AdHocSqlConnection
{
	#region Private Properties
	private string m_strName;
	#endregion

	#region Constructors
	public AdHocSqlConnection() { }

	public AdHocSqlConnection(string strName)
	{
		m_strName = strName;
	}
	#endregion

	#region Public Properties
	[XmlAttributeAttribute(AttributeName = "name", DataType = "string")]
	public string Name
	{
		get { return m_strName; }
		set { m_strName = value; }
	}
	#endregion
}

public class AdHocSqlStatement
{
	#region Private Properties
	private List<AdHocSqlParameter> m_oParameters;
	private string m_strStatement;
	private string m_strTitle;
	#endregion

	#region Constructors
	public AdHocSqlStatement() 
	{
		m_oParameters = new List<AdHocSqlParameter>();
	}

	public AdHocSqlStatement(string strTitle, string strStatement)
	{
		m_strStatement = strStatement;
		m_strTitle = strTitle;
	}
	#endregion

	#region Public Properties
	[XmlArray(ElementName = "Parameters", IsNullable = true),
	 XmlArrayItem(ElementName = "Parameter", IsNullable = true, Type = typeof(AdHocSqlParameter))]
	public List<AdHocSqlParameter> Parameters
	{
		get { return m_oParameters; }
		set { m_oParameters = value; }
	}
	[XmlElementAttribute(ElementName = "Title", DataType = "string")]
	public string Title
	{
		get { return m_strTitle; }
		set { m_strTitle = value; }
	}
	[XmlElementAttribute(ElementName = "Statement", DataType = "string")]
	public string Statement
	{
		get { return m_strStatement; }
		set { m_strStatement = value; }
	}
	#endregion
}

public class AdHocSqlParameter
{
	#region Private Properties
	private string m_strLabel;
	private string m_strName;
	private string m_strType;
	#endregion

	#region Constructors
	public AdHocSqlParameter()
	{
	}

	public AdHocSqlParameter(string strName, string strType, string strLabel)
	{
		m_strName = strName;
		m_strType = strType;
		m_strLabel = strLabel;
	}
	#endregion

	#region Public Properties
	[XmlAttributeAttribute(AttributeName = "name", DataType = "string")]
	public string Name
	{
		get { return m_strName; }
		set { m_strName = value; }
	}
	[XmlAttributeAttribute(AttributeName = "type", DataType = "string")]
	public string DataType
	{
		get { return m_strType; }
		set { m_strType = value; }
	}
	[XmlAttributeAttribute(AttributeName = "label", DataType = "string")]
	public string Label
	{
		get { return m_strLabel; }
		set { m_strLabel = value; }
	}
	#endregion
}
